Skip to main content

Streaming

BindAI v0.1 provides a streaming endpoint for agent execution through the REST API. Streaming allows a client to receive agent output progressively instead of waiting for the complete response. The endpoint is:
The endpoint requires API-key authentication.

Streaming Architecture

A streaming request follows this general flow:
The API uses FastAPI’s StreamingResponse to return the streamed output. The endpoint provides a lightweight HTTP streaming boundary around BindAI agent execution.

Endpoint

The streaming endpoint is:
The {agent_name} parameter identifies the configured agent that should execute the request. For example:
The exact agent name depends on the agents configured in the BindAI application.

Authentication

The streaming endpoint is protected by the BindAI API authentication layer. Clients must provide:
For example:
The configured API key is provided through:
See the Authentication documentation for the complete authentication model.

Request Body

The streaming endpoint accepts an agent run request. The request body contains:
The message field is required and must contain a non-empty string. The request model is the same request model used by the normal agent execution endpoint.

Streaming Response

The endpoint returns a streaming HTTP response. The response allows clients to consume agent output incrementally. Conceptually:
The exact amount of data delivered in each chunk depends on the underlying execution. Clients should therefore not assume a fixed number of chunks or a particular chunk size.

Streaming with cURL

A simple command-line example is:
The -N option tells cURL not to buffer the streamed response unnecessarily.

Streaming with Python

A Python HTTP client can consume the response incrementally. For example, using requests:
The client processes each received chunk as it arrives.

Streaming with JavaScript

A browser or server-side JavaScript application can consume the HTTP response using the Fetch API. For example:
The client can append each received chunk to the application’s output interface.

Streaming vs Normal Execution

BindAI provides both normal and streaming agent execution. Normal execution:
Streaming execution:
The conceptual difference is:
and:
Normal execution is convenient when the client needs the complete result before continuing. Streaming is useful when the client wants to display generated output incrementally.

When to Use Streaming

Streaming is particularly useful for interactive applications. Examples include:
  • Chat interfaces
  • Agent consoles
  • Interactive assistants
  • Long model responses
  • Generated explanations
  • Content generation
  • Developer tools
A user interface can display output while the agent is still producing it rather than waiting for the complete response.

Streaming and Model Providers

The REST API provides the HTTP streaming boundary around agent execution. The agent and its configured model provider determine how the underlying execution produces output. Conceptually:
Different providers may produce output at different rates. Clients should therefore treat the response as an incremental stream rather than relying on provider-specific timing.

Chunk Handling

Clients should treat received data as part of a larger response. A chunk may not represent:
  • A complete sentence
  • A complete word
  • A complete semantic unit
  • A complete application-level event
For example:
A client should combine chunks when displaying the complete generated response. Do not build application logic that assumes each chunk is independently meaningful.

Buffering

Streaming can be affected by buffering at different layers. Potential buffering points include:
A reverse proxy or hosting platform may buffer responses even when the application itself is streaming. When deploying streaming applications, verify that the surrounding infrastructure supports streaming responses.

Reverse Proxies

If a reverse proxy is placed in front of BindAI:
the proxy must be configured appropriately for streaming traffic. Otherwise, the proxy may collect response data before forwarding it to the client. The exact configuration depends on the reverse proxy and hosting platform. BindAI does not control infrastructure-level response buffering.

Connection Lifetime

A streaming request remains active while the HTTP response is being produced. Conceptually:
Clients should keep the HTTP connection open until the stream completes or an error occurs. Infrastructure should also use appropriate request and connection timeouts for streaming workloads.

Client Disconnects

A client may disconnect before the response has completed. For example:
Applications should not assume that the client will always remain connected for the entire execution. The behavior of an agent execution after a client disconnect depends on the underlying application and execution lifecycle. Streaming should therefore not be treated as a durable background execution mechanism. For work that must continue independently of the client connection, use the background run API instead.

Streaming vs Background Runs

Streaming and background execution solve different problems. Streaming:
Background execution:
Use streaming when the client wants to consume output during an active request. Use background runs when execution should be submitted and queried independently. The v0.1 background execution model is process-local. It is not a distributed durable queue.

Streaming and Authentication Errors

Authentication is checked before the protected streaming endpoint can be used. A missing or invalid API key results in an authentication error rather than a stream. For example:
A valid request proceeds to agent execution.

Streaming and Agent Errors

A validly authenticated request can still fail during execution. Potential failure sources include:
  • Agent configuration
  • Model providers
  • Tools
  • Connections
  • External services
  • Application code
Streaming should therefore be treated as an execution response, not as a guarantee of successful completion. Clients should handle connection failures and incomplete streams appropriately.

Streaming and Tools

An agent may use tools during execution. Conceptually:
The streaming endpoint provides the HTTP output stream for the agent execution. The current v0.1 streaming API should not be treated as a structured event stream for every internal model, tool, workflow, or connection event. For internal execution observability, BindAI provides the runtime event system and EventRecorder.

Streaming and Observability

BindAI’s runtime event system can record structured execution events independently of the HTTP streaming response. Relevant event categories include:
  • Agent started
  • Agent finished
  • Model requested
  • Model responded
  • Tool executed
  • Workflow events
  • Node events
  • Memory events
  • MCP connection events
This creates two distinct concerns:
and:
The streaming response should not be assumed to contain all runtime events.

Content Type

The current v0.1 streaming route returns a text-based StreamingResponse. Clients should consume it as streamed text. The current implementation is not documented as a Server-Sent Events (text/event-stream) protocol. Applications should therefore avoid assuming SSE-specific framing or event fields. If a future BindAI release introduces a structured streaming protocol, that protocol will be documented separately.

Streaming Protocol Scope

The current v0.1 streaming implementation intentionally provides a simple HTTP streaming interface. It does not define a complete structured event protocol for:
  • Token metadata
  • Tool-call events
  • Tool results
  • Structured model events
  • Usage events
  • Reasoning events
  • Workflow events
  • Connection events
Applications requiring these details should use the BindAI runtime event system or implement an application-specific event layer. A future release may provide a richer structured streaming protocol.

API Documentation

FastAPI automatically exposes API documentation for the BindAI API application. When running locally, the documentation is available through the standard FastAPI documentation routes. For example:
The OpenAPI schema is also available from the running API. The generated documentation reflects the installed BindAI API version.

Testing Streaming

The API package includes tests for the implemented agent API, including streaming behavior. Run the API test suite with:
Streaming behavior should be validated for:
  • Endpoint availability
  • Authentication
  • Agent lookup
  • Request validation
  • Streaming response behavior
  • Returned agent output
Provider-specific streaming behavior should be tested separately where required.

Local Development

Start the API locally with:
Then call:
with:
and:

Production Considerations

When deploying streaming endpoints publicly, consider:
  • HTTPS
  • Reverse-proxy buffering
  • Request timeouts
  • Connection timeouts
  • Client disconnects
  • API authentication
  • Rate limiting
  • Provider latency
  • Concurrent streams
  • Resource usage
  • Monitoring
Streaming requests can remain open longer than ordinary request/response operations. Infrastructure limits should therefore be configured for the expected workload.

Current v0.1 Scope

BindAI v0.1 provides:
  • Agent streaming through the REST API
  • Bearer API-key authentication
  • HTTP streaming responses
  • Python HTTP client compatibility
  • JavaScript Fetch compatibility
  • cURL compatibility
  • FastAPI/OpenAPI documentation
The current implementation is intentionally lightweight. It does not provide a standardized structured streaming event protocol. It does not turn the streaming endpoint into a durable background execution system. It does not provide distributed streaming coordination.

Future Streaming Capabilities

Future BindAI releases may expand streaming with capabilities such as:
  • Structured streaming events
  • Token metadata
  • Tool-call events
  • Tool-result events
  • Usage information
  • Execution identifiers
  • Stream cancellation
  • Richer error events
  • Server-Sent Events support
  • WebSocket support
  • Structured workflow streaming
These capabilities are not required for the BindAI v0.1 release.

Summary

BindAI v0.1 exposes agent streaming through:
Requests require:
and:
The endpoint returns a text-based streaming HTTP response that allows clients to consume agent output incrementally. Streaming is useful for interactive applications, but it should not be confused with background execution or runtime observability. The current architecture separates:
This lightweight streaming API provides the foundation for interactive BindAI applications while leaving richer structured streaming protocols for future releases.